<?php include "include/function_library.php"; ?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php include "html/header.html"; ?>

</head>
<body class="tcuk home">

	<div id="wp">
	
		<?php  include "html/menu.html"; ?>
		
		<div id="ct">	
			
			<?php 
				$date_selected = false;
				$date;
				if(post("date_selected")) {
					$date 	= post("date");
					$date_selected = true;
				}
			?>
			<div style="margin-top:20px; margin-left:auto; margin-right:auto; width: 70%;">
				<h2>Show Hotel Capacity</h2><br /><br />
				<form action="<?php echo curPageURL(); ?>" method="post">
					Select a date too see available hotel capacities at that date;<br />
					<input type="date" id="date" name="date" value="" placeholder="Date.." style="width: 120px;"/>
					<input type="submit" id="date_selected" name="date_selected" value="Select" style="width: 90px; height:30px; margin-left: 10px;"/>
				</form>
			</div>
			
			<?php 
				if($date_selected == true) { ?>
					
				<table border="">
					<thead>
						<tr>
							<th>Hotel name</th>
							<th>Total Capacity</th>
							<th>Used Capacity</th>
							<th>Remaining Capacity</th>
						</tr>
					</thead>
					<tbody>
						<?php 
							$query="select 
									h.id as id,
									h.name as hotel_name, 
									h.capacity as total_capacity,
									(select count(*) from hotel_purchase hp where h.id=hp.hotel_id and hp.start_date<='$date' and hp.end_date>'$date') as used_capacity,
									(h.capacity - (select count(*) from hotel_purchase hp where h.id=hp.hotel_id and hp.start_date<='$date' and hp.end_date>'$date')) as remaining_capacity
									from hotel h";
							
							$result = sql_query($query);
							
							while($tuple = mysql_fetch_assoc($result)) {
								?>
								<tr>
									<td><a href="hotel_detail.php?id=<?php echo $tuple["id"]; ?>"><?php echo $tuple["hotel_name"]; ?></a></td>
									<td><?php echo $tuple["total_capacity"]; ?></td>
									<td><?php echo $tuple["used_capacity"]; ?></td>
									<td><?php echo $tuple["remaining_capacity"]; ?></td>
								</tr>
								<?php
							}
						?>
					</tbody>
				</table>
			<?php }?>
		
		</div> 	
		<!-- CONTENT ENDS-->		
		
		<?php include "html/footer.html"; ?>
		
	</div>
	
</body>
</html>